//
// Created by lymk on 2021/8/6.
//

#include "Utils.h"
#include "stb_image.h"
#include "iostream"

PicData LoadPNG(std::string path) {
    int width = 10;
    int height = 100;
    int nrChannels;
    unsigned char* data = stbi_load(path.c_str(), &width, &height, &nrChannels, 0);
    if(data == nullptr){
        std::cout<<"failed"<<std::endl;
        return {};
    }
    for(int i=0;i<height;i++){
        for(int j=0;j<width;j++){
            int idx = width * nrChannels * i + j * nrChannels;
            double alpha = (float)data[idx + 3]/255.0;
            int t = data[idx];
            data[idx] = data[idx + 2] * (int)alpha;
            data[idx+2] = t * (int)alpha;
            data[idx+1] = data[idx] * (int)alpha;
        }
    }
    return {data,width,height,nrChannels};
}

float Round_P(float input) {
    int tmp = input;
    return (float)tmp;
}

void CoolUtil::Update(double DeltaSeconds) {
    now_cool_time -= DeltaSeconds;
    if(now_cool_time <= 0){
        flag = true;
    }
}
